<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<!--只配置基本dao信息  -->
<mapper namespace="${config.pack}.mappers.${beanName}Mapper">

${"\t"}<resultMap type="${beanName}" id="base${beanName}ResultMap">
${"\t"}${"\t"}<id property="${columnList[0].javaPropertyName}" column="${columnList[0].dbColumnName}"  jdbcType="${columnList[0].mybatisJdbcType}"/>
		<#list columnList as column>
			<#if column_index!=0>
${"\t"}${"\t"}<result property="${column.javaPropertyName}" column="${column.dbColumnName}" jdbcType="${column.mybatisJdbcType}"/>		
			</#if>
		</#list>
${"\t"}</resultMap>

${"\t"}<resultMap type="${beanName}" id="${simpleBeanName}ResultMap" extends="base${beanName}ResultMap">
${"\t"}</resultMap>

${"\t"}<insert id="add" parameterType="${beanName}">
${"\t"}${"\t"}INSERT INTO ${config.tblName} (<#list columnList as column>${column.dbColumnName}<#if column_has_next>,</#if></#list>) VALUES (
<#list columnList as column>
${"\t"}${"\t"}${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"}<#if column_has_next>,</#if>
</#list>
${"\t"}${"\t"})
${"\t"}</insert>

${"\t"}<update id="editNotBlank" parameterType="${beanName}">
${"\t"}${"\t"}UPDATE ${config.tblName} 
${"\t"}${"\t"}<set>
			<#list columnList as column>
			<#if column_index!=0>
${"\t"}${"\t"}${"\t"}<if test="${column.javaPropertyName} != null and ${column.javaPropertyName} !='' ">
${"\t"}${"\t"}${"\t"}${"\t"}${column.dbColumnName} = ${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"}, 
${"\t"}${"\t"}${"\t"}</if>			
			</#if>
			</#list>
${"\t"}${"\t"}</set>
${"\t"}${"\t"}WHERE ${columnList[0].dbColumnName} = ${r"#{"}${columnList[0].javaPropertyName}${r"}"} 
${"\t"}</update>

${"\t"}<delete id="deleteById" parameterType="string">
${"\t"}${"\t"}DELETE FROM ${config.tblName} WHERE ${columnList[0].dbColumnName} = ${r"#{"}value${r"}"}
${"\t"}</delete>

${"\t"}<select id="getById" resultMap="${simpleBeanName}ResultMap" parameterType="string">
${"\t"}${"\t"}SELECT * FROM ${config.tblName} WHERE ${columnList[0].dbColumnName} = ${r"#{"}value${r"}"}
${"\t"}</select>

${"\t"}<select id="listByWhere" resultMap="${simpleBeanName}ResultMap" parameterType="${beanName}">
${"\t"}${"\t"}SELECT * FROM ${config.tblName}
${"\t"}${"\t"}<include refid="whereSQL"/>
${"\t"}</select>

${"\t"}<select id="getByWhere" resultMap="${simpleBeanName}ResultMap" parameterType="${beanName}">
${"\t"}${"\t"}SELECT * FROM ${config.tblName}
${"\t"}${"\t"}<include refid="whereSQL"/>
${"\t"}</select>

${"\t"}<select id="countByWhere" resultType="long" parameterType="${beanName}">
${"\t"}${"\t"}SELECT count(*) FROM ${config.tblName}
${"\t"}${"\t"}<include refid="whereSQL"/>
${"\t"}</select>

${"\t"}<sql id="whereSQL">
${"\t"}${"\t"}<where>
<#list columnList as column>
${"\t"}${"\t"}${"\t"}<if test="${column.javaPropertyName} != null and ${column.javaPropertyName} !='' ">
${"\t"}${"\t"}${"\t"}${"\t"}AND	${column.dbColumnName} = ${r"#{"}${column.javaPropertyName}, jdbcType=${column.mybatisJdbcType}${r"}"}
${"\t"}${"\t"}${"\t"}</if>			
</#list>
${"\t"}${"\t"}</where>	
${"\t"}</sql>	

</mapper>
